package com.atguigu.ct.analysis.reducer;

import com.atguigu.ct.analysis.kv.AnalysisKey;
import com.atguigu.ct.analysis.kv.AnalysisValue;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * Description: 分析数据的Reducer
 * @Author: yyx
 * @Create: 2023/5/5 19:48
 * @Version: 8
 */
public class AnalysisBeanReducer extends Reducer<AnalysisKey,Text,AnalysisKey, AnalysisValue> {
    @Override
    protected void reduce(AnalysisKey key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        int sumCall = 0;
        int sumDuration = 0;

        for (Text value : values) {
            int duration = Integer.parseInt(value.toString());
            sumDuration = sumDuration + duration;
            sumCall++;
        }

        context.write(key,new AnalysisValue(""+sumCall,""+sumDuration));
    }
}
